package com.example.u14;

import java.lang.reflect.Proxy;

public class SimpleDynamicProxy {

    public static void consumer(Interface iface){
        iface.doSomething();
        iface.someThingElse("bonobo");
    }

    public static void main(String[] args) {
        RealObject realObject = new RealObject();
        consumer(realObject);

        // 使用代理
        Interface proxy = (Interface) Proxy.newProxyInstance(
                Interface.class.getClassLoader(),
                new Class[]{Interface.class},
                new DynamicProxyHandler(realObject));
        consumer(proxy);
    }
}
